

<!DOCTYPE html>
<html lang="zh-CN">

<head><meta name="generator" content="Hexo 3.9.0">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>AdroidX 下使用 Activity 和 Fragment 的变化 - 杨云召 | 博客</title>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="google" content="notranslate">

  
  
  <meta name="description" content="过去的一段时间，AndroidX 软件包下的 Acti..."> 
  
  <meta name="author" content="杨云召（Flywith24）"> 

  
    <link rel="icon" href="/images/icons/favicon-16x16.png" type="image/png" sizes="16x16">
  
  
    <link rel="icon" href="/images/icons/favicon-32x32.png" type="image/png" sizes="32x32">
  
  
    <link rel="apple-touch-icon" href="/images/icons/apple-touch-icon.png" sizes="180x180">
  
  
    <meta rel="mask-icon" href="/images/icons/stun-logo.svg" color="#333333">
  
  
    <meta rel="msapplication-TileImage" content="/images/icons/favicon-144x144.png">
    <meta rel="msapplication-TileColor" content="#000000">
  

  <link rel="stylesheet" href="/css/style.css">

  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1445822_hhodbqn7tit.css">
  

  
  
  <link rel="stylesheet" href="https://cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.css">
  

  
  
  <link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.18.1/styles/xcode.min.css">
  

  <script>
    var CONFIG = window.CONFIG || {};
    var ZHAOO = window.ZHAOO || {};
    CONFIG = {
      isHome: false,
      fancybox: true,
      pjax: false,
      lazyload: {
        enable: true,
        loadingImage: '/images/theme/loading.gif',
      },
      donate: {
        enable: true,
        alipay: 'https://gitee.com/flywith24/Album/raw/master/img/20201015113301.jpg',
        wechat: 'https://gitee.com/flywith24/Album/raw/master/img/20201015112814.png'
      },
      motto: {
        api: '',
        default: '不人云亦云，只求接近真相.'
      },
      galleries: {
        enable: true
      },
      fab: {
        enable: true,
        alwaysShow: false
      },
      carrier: {
        enable: true
      },
      daovoice: {
        enable: true
      }
    }
  </script>

  

  
</head></html>
<body class="lock-screen">
  <div class="loading"></div>
  


<nav class="navbar">
  <div class="left"></div>
  <div class="center">AdroidX 下使用 Activity 和 Fragment 的变化</div>
  <div class="right">
    <i class="iconfont iconmenu j-navbar-menu"></i>
  </div>
</nav>

  <nav class="menu">
  <div class="menu-wrap">
    <div class="menu-close">
      <i class="iconfont iconbaseline-close-px"></i>
    </div>
    <ul class="menu-content">
      
      
      
      
      <li class="menu-item"><a href="/ " class="underline"> 首页</a></li>
      
      
      
      
      <li class="menu-item"><a href="/archives " class="underline"> 归档</a></li>
      
      
      
      
      <li class="menu-item"><a href="/tags " class="underline"> 标签</a></li>
      
      
      
      
      <li class="menu-item"><a href="/categories " class="underline"> 分类</a></li>
      
      
      
      
      <li class="menu-item"><a href="/about " class="underline"> 关于</a></li>
      
    </ul>
    <div class="menu-copyright"><p>Copyright© 2017 - 2020 ❤️ Flywith24</p></div>
  </div>
</nav>
  <main id="main">
  <div class="container" id="container">
    <article class="article">
  <div class="wrap">
    <section class="head">
  <img   class="lazyload" data-original="https://gitee.com/flywith24/Album/raw/master/img/20201015093624.png" src=""  draggable="false">
  <div class="head-mask">
    <h1 class="head-title">AdroidX 下使用 Activity 和 Fragment 的变化</h1>
    <div class="head-info">
      <span class="post-info-item"><i class="iconfont iconcalendar"></i>二月 29, 2020</span
        class="post-info-item">
      
      <span class="post-info-item"><i class="iconfont iconfont-size"></i>6065</span>
    </div>
  </div>
</section>
    <section class="main">
      <section class="content">
        <blockquote>
<p>原文：<a href="https://medium.com/@miloszlewandowski/how-androidx-changes-the-way-we-work-with-activities-and-fragments-73b88d157678" target="_blank" rel="noopener">How AndroidX changes the way we work with Activities and Fragments</a></p>
<p>作者：<a href="https://medium.com/@miloszlewandowski" target="_blank" rel="noopener">Miłosz Lewandowski</a></p>
<p>译者：<a href="http://www.yangyunzhao.com/" target="_blank" rel="noopener">Flywith24</a></p>
</blockquote>
<h3 id="在构造器中传入布局-ID"><a href="#在构造器中传入布局-ID" class="headerlink" title="在构造器中传入布局 ID"></a>在构造器中传入布局 ID</h3><p>从 <code>AndroidX</code>  <code>AppCompat 1.1.0</code> 和 <code>Fragment 1.1.0</code> ( 译者注：AppCompat 包含 Fragment，且 Fragment 包含 Activity，详情见<a href="https://juejin.im/post/5e567ee1518825494466a938" target="_blank" rel="noopener">【整理】Jetpack 主要组件的依赖及传递关系</a> )开始，您可以使用将 <code>layoutId</code> 作为参数的构造函数：</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs kotlin"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyActivity</span> : <span class="hljs-type">AppCompatActivity</span></span>(R.layout.my_activity)<br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyFragmentActivity</span>: <span class="hljs-type">FragmentActivity</span></span>(R.layout.my_fragment_activity)<br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyFragment</span> : <span class="hljs-type">Fragment</span></span>(R.layout.my_fragment)<br></code></pre></td></tr></table></figure>

<p>这种方法可以减少 <code>Activity/Fragment</code> 中方法重写的数量，并使类更具可读性。 无需在 <code>Activity</code> 中重写 <code>onCreate()</code> 即可调用 <code>setContentView()</code> 方法。 另外，无需手动在<code>Fragment</code> 中重写 <code>onCreateView</code> 即可手动调用 <code>Inflater</code> 来扩展视图。</p>
<h3 id="扩展-Activity-Fragment-的灵活性"><a href="#扩展-Activity-Fragment-的灵活性" class="headerlink" title="扩展 Activity/Fragment 的灵活性"></a>扩展 <code>Activity/Fragment</code> 的灵活性</h3><p>借助 <code>AndroidX</code> 新的 API ，可以减少在 <code>Activity/Fragment</code> 处理某些功能的情况。通常，您可以获取提供某些功能的对象并向其注册您的处理逻辑，而不是重写 <code>Activity / Fragment</code> 中的方法。 这样，您现在可以在屏幕上组成几个独立的类，获得更高的灵活性，复用代码，并且通常在不引入自己的抽象的情况下，对代码结构具有更多控制。 让我们看看这在两个示例中如何工作。</p>
<h4 id="1-OnBackPressedDispatcher"><a href="#1-OnBackPressedDispatcher" class="headerlink" title="1. OnBackPressedDispatcher"></a>1. OnBackPressedDispatcher</h4><p>有时，您需要阻止用户返回上一级。 在这种情况下，您需要在 <code>Activity</code> 中重写 <code>onBackPressed()</code> 方法。 但是，当您使用 <code>Fragment</code> 时，没有直接的方法来拦截返回。 在 <code>Fragment</code> 类中没有可用的 <code>onBackPressed()</code> 方法，这是为了防止同时存在多个 <code>Fragment</code> 时发生意外行为。</p>
<p>但是，从 <code>AndroidX</code> <code>Activity 1.0.0</code> 开始，您可以使用 <code>OnBackPressedDispatcher</code> 在您可以访问该 <code>Activity</code> 的代码的任何位置（例如，在 <code>Fragment</code> 中）注册 <code>OnBackPressedCallback</code>。</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs kotlin"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyFragment</span> : <span class="hljs-type">Fragment</span></span>() &#123;<br>  <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">onAttach</span><span class="hljs-params">(context: <span class="hljs-type">Context</span>)</span></span> &#123;<br>    <span class="hljs-keyword">super</span>.onAttach(context)<br>    <span class="hljs-keyword">val</span> callback = <span class="hljs-keyword">object</span> : OnBackPressedCallback(<span class="hljs-literal">true</span>) &#123;<br>      <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">handleOnBackPressed</span><span class="hljs-params">()</span></span> &#123;<br>        <span class="hljs-comment">// Do something</span><br>      &#125;<br>    &#125;<br>    requireActivity().onBackPressedDispatcher.addCallback(<span class="hljs-keyword">this</span>, callback)<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>您可能会在这里注意到另外两个有用的功能：</p>
<ul>
<li><code>OnBackPressedCallback</code> 的构造函数中的布尔类型的参数有助于根据当前状态动态 打开/关闭按下的行为</li>
<li><code>addCallback()</code> 方法的可选第一个参数是 <code>LifecycleOwner</code>，以确保仅在您的生命周期感知对象（例如，<code>Fragment</code>）至少处于 <code>STARTED</code> 状态时才使用回调。</li>
</ul>
<p>通过使用 <code>OnBackPressedDispatcher</code> ，您不仅可以获得在 <code>Activity</code> 之外处理返回键的便捷方式。 根据您的需要，您可以在任意位置定义 <code>OnBackPressedCallback</code>，使其可复用，或根据应用程序的架构进行任何操作。 您不再需要重写<code>Activity</code> 中的 <code>onBackPressed</code> 方法，也不必提供自己的抽象的来实现需求的代码。</p>
<h4 id="2-SavedStateRegistry"><a href="#2-SavedStateRegistry" class="headerlink" title="2. SavedStateRegistry"></a>2. SavedStateRegistry</h4><p>如果您希望 <code>Activity</code> 在终止并重启后恢复之前的状态，则可能要使用 <code>saved state</code> 功能。 过去，您需要在 <code>Activity</code> 中重写两个方法：<code>onSaveInstanceState</code> 和 <code>onRestoreInstanceState</code>。 您还可以在 <code>onCreate</code> 方法中访问恢复的状态。 同样，在 <code>Fragment</code> 中，您可以使用<code>onSaveInstanceState</code> 方法（并且可以在 <code>onCreate</code>，<code>onCreateView</code> 和<code>onActivityCreated</code>方法中恢复状态）。</p>
<p>从 <code>AndroidX</code>  <code>SavedState 1.0.0</code>（它是 <code>AndroidX</code> <code>Activity</code> 和 <code>AndroidX</code>  <code>Fragment</code> 内部的依赖。译者注：您不需要单独声明它）开始，您可以访问 <code>SavedStateRegistry</code>，它使用了与前面描述的 <code>OnBackPressedDispatcher</code> 类似的机制：您可以从 <code>Activity / Fragment</code> 中获取 <code>SavedStateRegistry</code>，然后 注册您的 <code>SavedStateProvider</code>：</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs kotlin"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyActivity</span> : <span class="hljs-type">AppCompatActivity</span></span>() &#123;<br><br>  <span class="hljs-keyword">companion</span> <span class="hljs-keyword">object</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">val</span> MY_SAVED_STATE_KEY = <span class="hljs-string">"my_saved_state"</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">val</span> SOME_VALUE_KEY = <span class="hljs-string">"some_value"</span><br>  &#125;<br>    <br>  <span class="hljs-keyword">private</span> <span class="hljs-keyword">lateinit</span> <span class="hljs-keyword">var</span> someValue: String<br>    <br>  <span class="hljs-keyword">private</span> <span class="hljs-keyword">val</span> savedStateProvider = SavedStateRegistry.SavedStateProvider &#123;    <br>    Bundle().apply &#123;<br>      putString(SOME_VALUE_KEY, someValue)<br>    &#125;<br>  &#125;<br>  <br>  <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">onCreate</span><span class="hljs-params">(savedInstanceState: <span class="hljs-type">Bundle</span>?)</span></span> &#123;    <br>    <span class="hljs-keyword">super</span>.onCreate(savedInstanceState)<br>    savedStateRegistry<br>      .registerSavedStateProvider(MY_SAVED_STATE_KEY, savedStateProvider)<br>  &#125;<br>  <br>  <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">someMethod</span><span class="hljs-params">()</span></span> &#123;<br>    someValue = savedStateRegistry<br>      .consumeRestoredStateForKey(MY_SAVED_STATE_KEY)<br>      ?.getString(SOME_VALUE_KEY)<br>      ?: <span class="hljs-string">""</span><br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>如您所见，<code>SavedStateRegistry</code> 强制您将密钥用于数据。 这样可以防止您的数据被 attach 到同一个 <code>Activity/Fragment</code>的另一个 <code>SavedStateProvider</code> 破坏。 就像在 <code>OnBackPressedDispatcher</code> 中一样，您可以例如将 <code>SavedStateProvider</code> 提取到另一个类，通过使用所需的任何逻辑使其与数据一起使用，从而在应用程序中实现清晰的保存状态行为。</p>
<p>此外，如果您在应用程序中使用 <code>ViewModel</code>，请考虑使用 <code>AndroidX</code>  <code>ViewModel-SavedState</code> 使你的<code>ViewModel</code> 可以保存其状态。 为了方便起见，从 <code>AndroidX</code>  <code>Activity 1.1.0</code> 和 <code>AndroidX</code> <code>Fragment 1.2.0</code> 开始，启用 <code>SavedState</code> 的<code>SavedStateViewModelFactory</code> 是在获取 <code>ViewModel</code> 的所有方式中使用的默认工厂：委托 <code>ViewModelProvider</code> 构造函数和 <code>ViewModelProviders.of()</code> 方法。</p>
<h3 id="FragmentFactory"><a href="#FragmentFactory" class="headerlink" title="FragmentFactory"></a>FragmentFactory</h3><p><code>Fragment</code> 最常提及的问题之一是不能使用带有参数的构造函数。 例如，如果您使用 <code>Dagger2</code> 进行依赖项注入，则无法使用 <code>Inject</code> 注解 <code>Fragment</code> 构造函数并指定参数。 现在，您可以通过指定 <code>FragmentFactory</code> 类来减少 <code>Fragment</code> 创建过程中的类似问题。 通过在 <code>FragmentManager</code> 中注册 <code>FragmentFactory</code>，可以重写实例化 <code>Fragment</code> 的默认方法：</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs kotlin"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyFragmentFactory</span> : <span class="hljs-type">FragmentFactory</span></span>() &#123;<br><br>  <span class="hljs-keyword">override</span> <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">instantiate</span><span class="hljs-params">(classLoader: <span class="hljs-type">ClassLoader</span>, className: <span class="hljs-type">String</span>)</span></span>: Fragment &#123;<br>    <span class="hljs-comment">// Call loadFragmentClass() to obtain the Class object</span><br>    <span class="hljs-keyword">val</span> fragmentClass = loadFragmentClass(classLoader, className)<br>     <br>    <span class="hljs-comment">// Now you can use className/fragmentClass to determine your prefered way </span><br>    <span class="hljs-comment">// of instantiating the Fragment object and just do it here.</span><br>        <br>    <span class="hljs-comment">// Or just call regular FragmentFactory to instantiate the Fragment using</span><br>    <span class="hljs-comment">// no arguments constructor</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-keyword">super</span>.instantiate(classLoader, className)<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>如您所见，该API非常通用，因此您可以执行想要创建 <code>Fragment</code> 实例的所有操作。 回到 <code>Dagger2</code> 示例，例如，您可以注入<code>FragmentFactory Provider &lt;Fragment&gt;</code> 并使用它来获取 <code>Fragment</code> 对象。</p>
<h3 id="测试-Fragment"><a href="#测试-Fragment" class="headerlink" title="测试 Fragment"></a>测试 Fragment</h3><p>从<code>AndroidX</code>  <code>Fragment 1.1.0</code> 开始，可以使用 <code>Fragment</code> 测试组件提供 <code>FragmentScenario</code> 类，该类可以帮助在测试中实例化 <code>Fragment</code> 并进行单独测试：</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs kotlin"><span class="hljs-comment">// To launch a Fragment with a user interface:</span><br><span class="hljs-keyword">val</span> scenario = launchFragmentInContainer&lt;FirstFragment&gt;()<br>        <br><span class="hljs-comment">// To launch a headless Fragment:</span><br><span class="hljs-keyword">val</span> scenario = launchFragment&lt;FirstFragment&gt;()<br>        <br><span class="hljs-comment">// To move the fragment to specific lifecycle state:</span><br>scenario.moveToState(CREATED)<br><br><span class="hljs-comment">// Now you can e.g. perform actions using Espresso:</span><br>onView(withId(R.id.refresh)).perform(click())<br><br><span class="hljs-comment">// To obtain a Fragment instance:</span><br>scenario.onFragment &#123; fragment -&gt;<br>  ...<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="More-Kotlin"><a href="#More-Kotlin" class="headerlink" title="More Kotlin!"></a>More Kotlin!</h3><p>很高兴看到 <code>-ktx</code> <code>AndroidX</code> 软件包中提供了许多有用的 <code>Kotlin</code> 扩展方法，并且定期添加了新的方法。 例如，在<code>AndroidX</code> <code>Fragment-KTX 1.2.0</code> 中，使用片段化类型的扩展名可用于 <code>FragmentTransaction</code> 上的 <code>replace()</code> 方法。 将其与 <code>commit()</code> 扩展方法结合使用，我们可以获得以下代码：</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs kotlin"><span class="hljs-comment">// Before</span><br>supportFragmentManager<br>  .beginTransaction()<br>  .add(R.id.container, MyFragment::<span class="hljs-class"><span class="hljs-keyword">class</span>.<span class="hljs-title">java</span>, <span class="hljs-type">null)</span></span><br>  .commit()<br><br><span class="hljs-comment">// After</span><br>supportFragmentManager.commit &#123;<br>  replace&lt;MyFragment&gt;(R.id.container)<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="FragmentContainerView"><a href="#FragmentContainerView" class="headerlink" title="FragmentContainerView"></a>FragmentContainerView</h3><p>一件小而重要的事情。 如果您将 <code>FrameLayout</code> 用作 <code>Fragment</code> 的容器，则应改用 <code>FragmentContainerView</code> 。 它修复了一些动画 z轴索引顺序问题和窗口插入调度。 从 <code>AndroidX</code> <code>Fragment 1.2.0</code> 开始可以使用 <code>FragmentContainerView</code>。</p>
<hr>
<h3 id="关于我"><a href="#关于我" class="headerlink" title="关于我"></a>关于我</h3><hr>
<p>我是 <a href="https://flywith24.gitee.io/">Fly_with24</a></p>
<ul>
<li><p><a href="https://juejin.im/user/57c7f6870a2b58006b1cfd6c" target="_blank" rel="noopener">掘金</a></p>
</li>
<li><p><a href="https://www.jianshu.com/u/3d5ad6043d66" target="_blank" rel="noopener">简书</a></p>
</li>
<li><p><a href="https://github.com/Flywith24" target="_blank" rel="noopener">Github</a></p>
</li>
</ul>
      </section>
      <section class="extra">
        
        <ul class="copyright">
  
  <li><strong>本文作者：</strong>杨云召（Flywith24）</li>
  <li><strong>本文链接：</strong><a href="https://flywith24.gitee.io/2020/02/29/Jetpack-androidx-activity-fragment/index.html">https://flywith24.gitee.io/2020/02/29/Jetpack-androidx-activity-fragment/index.html</a></li>
  <li><strong>版权声明：</strong>本博客所有文章均采用<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh"
      rel="external nofollow" target="_blank"> BY-NC-SA </a>许可协议，转载请注明出处！</li>
  
</ul>
        
        
        <section class="donate">
  <div class="qrcode">
    <img   class="lazyload" data-original="https://gitee.com/flywith24/Album/raw/master/img/20201015113301.jpg" src="" >
  </div>
  <div class="icon">
    <a href="javascript:;" id="alipay"><i class="iconfont iconalipay"></i></a>
    <a href="javascript:;" id="wechat"><i class="iconfont iconwechat-fill"></i></a>
  </div>
</section>
        
        
  <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Jetpack/">Jetpack</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MVVM/">MVVM</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/androidx/">androidx</a></li></ul>

        
<nav class="nav">
  
    <a href="/2020/03/01/Jetpack-dependencies/"><i class="iconfont iconleft"></i>Jetpack 主要依赖关系</a>
  
  
    <a href="/2019/11/29/relearn-task-back-stack/">【重学Android读书笔记】Activity的任务栈与返回栈<i class="iconfont iconright"></i></a>
  
</nav>

      </section>
      
      <section class="comments">
  
  <div class="btn" id="comments-btn">查看评论</div>
  
  
<div id="valine"></div>
<script defer src="//unpkg.com/valine/dist/Valine.min.js"></script>
<script>
  window.onload = function () {
    var loadValine = function () {
      new Valine({
        el: '#valine',
        app_id: "SHA3gzCcxFlqaPcGRnX4UgET-gzGzoHsz",
        app_key: "OYo7ITS4AzTvBUvb1yIY8oaf",
        placeholder: "期待你的留言",
        avatar: "mp",
        pageSize: "10",
        lang: "zh-CN",
      });
    }
    if ( true ) {
      $("#comments-btn").on("click", function () {
        $(this).hide();
        loadValine();
      });
    } else {
      loadValine();
    }
  };
</script>

</section>
      
    </section>
  </div>
</article>
  </div>
</main>
  <footer class="footer">
  <div class="footer-social">
    
    
    
    
    
    <a href="tencent://message/?Menu=yes&uin=1032367864 " target="_blank" onMouseOver="this.style.color= '#12B7F5'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconQQ "></i>
    </a>
    
    
    
    
    
    <a href="javascript:; " target="_blank" onMouseOver="this.style.color= '#8bc34a'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconwechat-fill "></i>
    </a>
    
    
    
    
    
    <a href="https://flywith24.gitee.io/about/ " target="_blank" onMouseOver="this.style.color= '#d32f2f'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconheart "></i>
    </a>
    
    
    
    
    
    <a href="https://github.com/Flywith24 " target="_blank" onMouseOver="this.style.color= '#24292E'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  icongithub-fill "></i>
    </a>
    
    
    
    
    
    <a href="mailto:youngyunzhao@163.com " target="_blank" onMouseOver="this.style.color='#FFBE5B'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconmail"></i>
    </a>
    
  </div>
  <div class="footer-copyright"><p>Copyright© 2017 - 2020 ❤️ Flywith24</p></div>
</footer>
  
      <div class="fab fab-plus">
    <i class="iconfont iconplus"></i>
  </div>
  
  <div class="fab fab-daovoice">
    <i class="iconfont iconcomment"></i>
  </div>
  
  <div class="fab fab-up">
    <i class="iconfont iconcaret-up"></i>
  </div>
  
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":"tfalse"},"log":false});</script></body>

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>




<script src="https://cdn.bootcdn.net/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>




<script src="https://cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.js"></script>




<script src="/js/utils.js"></script>
<script src="/js/modules.js"></script>
<script src="/js/zui.js"></script>
<script src="/js/script.js"></script>




<script>
  (function (i, s, o, g, r, a, m) {
    i["DaoVoiceObject"] = r;
    i[r] = i[r] || function () {
      (i[r].q = i[r].q || []).push(arguments)
    }, i[r].l = 1 * new Date();
    a = s.createElement(o), m = s.getElementsByTagName(o)[0];
    a.async = 1;
    a.src = g;
    a.charset = "utf-8";
    m.parentNode.insertBefore(a, m)
  })(window, document, "script", ('https:' == document.location.protocol ? 'https:' : 'http:') +
    "//widget.daovoice.io/widget/0f81ff2f.js", "daovoice")
  daovoice('init', {
    app_id: "7785620b"
  }, {
    launcher: {
      disableLauncherIcon: true,
    },
  });
  daovoice('update');
</script>



<script>
  (function () {
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
      bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    } else {
      bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
  })();
</script>


<script>
  var _hmt = _hmt || [];
  (function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?4c204d8bc027a0455b5fc642ac334ca8";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>










</html>